﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using System.Data;
using System.Data.SqlClient;
using BEGDC.Utility.NHibernate;
using Castle.Services.Transaction;
using System.Collections;
using System.Xml;
using Castle.Facilities.NHibernateIntegration;
using BEGDC.Utility;

namespace BEGDC.PreContract.BLL
{
	public partial class ReportHistory: IReportHistory
	{
        //Joan 2008-09-25
        public DataTable GetReportHistory(string filter)
        {
            using (ISession session = factory.OpenSession())
            {
                string strSql = "SELECT TOP 15 ReportID,ReportDate,ReportType FROM ReportHistory";
                if (filter != string.Empty)
                    strSql += " WHERE " + filter;

                strSql += " ORDER BY ReportDate DESC";

                DataTable dtSearch = DAO.ExecuteDataTable(session, strSql);

                return dtSearch;
            }
        }
        public DataTable GetReportContentByID(long reportID)
        {
            using (ISession session = factory.OpenSession())
            {
                string strSql = "SELECT ReportID,ReportType,ReportDate,ReportContent FROM ReportHistory WHERE ReportID=" + reportID.ToString();

                DataTable dtSearch  = DAO.ExecuteDataTable(session, strSql);

                return dtSearch;
            }
        }

        public DataTable SaveHistoryReport(string rptDate, string rptType, string rptContent)
        {
            using (ISession session = factory.OpenSession())
            {
                SqlParameter[] paras = new SqlParameter[3];

                paras[0] = new SqlParameter("@ReportDate", SqlDbType.SmallDateTime);
                paras[0].Value = rptDate;
                paras[1] = new SqlParameter("@ReportType", SqlDbType.NVarChar,50);
                paras[1].Value = rptType;
                paras[2] = new SqlParameter("@ReportContent", SqlDbType.NText);
                paras[2].Value = rptContent;

                DataSet dtSet;
                dtSet=BEGDC.Utility.DataAccess.SQLServer.ExecuteDatasetBySp((SqlConnection)session.Connection, "sp_SaveReportHistory", paras);
                if (dtSet.Tables.Count > 0)
                    return dtSet.Tables[0];
                else
                    return null;
                
            }
        }
        //end


        //Edwin.fan 2008-9-29
        public DataTable GetReportType()
        {
            using (ISession session = factory.OpenSession())
            {
                string sqlString = String.Format("SELECT distinct  ReportType  FROM ReportHistory ORDER BY ReportType");

                DataTable dt = DAO.ExecuteDataTable(session, sqlString);

                return dt;
            }
        }
	}
}



